package blog.controller;

import blog.entity.Tag;
import blog.service.back.TagBackService;
import blog.util.back.ControllerUtil;
import blog.vo.back.AddTagVO;
import blog.vo.back.ByTagStatusGetAllTagVO;
import blog.vo.back.ByTagUuidGetTagInfoVO;
import blog.vo.back.UpdateTagInfoVO;
import blog.vo.common.PaginationVO;
import blog.vo.common.ResponseListObjectVO;
import blog.vo.common.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 　　* @description: TODO
 * 　　* @param
 * 　　* @return
 * 　　* @throws
 * 　　* @author Administrator
 * 　　* @date $ $
 *
 */
@Controller
@RequestMapping("/tag")
public class TagController {
    @Autowired
    private TagBackService tagBackService;

    @RequestMapping("/get-all-tag")
    public String getAllTag(PaginationVO paginationVO, Model model){
        List<Tag> allTag = tagBackService.getAllTag(paginationVO);
        model.addAttribute("allTag",new ResponseListObjectVO<Tag>(200,"ok",allTag).getResponseObject());
        return "home";
    }

    @PostMapping("/by-tag-status-get-all-tag")
    public String byTagStatusGetAllTag(ByTagStatusGetAllTagVO byTagStatusGetAllTag, Model model){
        List<Tag> allTag = tagBackService.byTagStatusGetAllTag(byTagStatusGetAllTag);
        model.addAttribute("allTag",new ResponseListObjectVO<Tag>(200,"ok",allTag).getResponseObject());
        return "home";
    }

    @RequestMapping("/byTagUuidGetTagInfo")
    public String byTagUuidGetTagInfo(ByTagUuidGetTagInfoVO byTagUuidGetTagInfoVO, Model model){
        Tag tag = tagBackService.byTagUuidGetTagInfo(byTagUuidGetTagInfoVO);
        model.addAttribute("tag",new ResponseVO<Tag>(200,"ok",tag).getResponseObject());
        return "tag";
    }

    @PostMapping("/add-tag")
    public String addTag(AddTagVO addTagVO,Model model){
        if (addTagVO.getTagName() == "" || addTagVO.getTagName() == null){
            return "redirect:/tag/get-all-tag";
        }
        int result = tagBackService.addTag(addTagVO);
        String addResultUrl = ControllerUtil.addResultUrl(result, "redirect:/tag/get-all-tag", model);
        return addResultUrl;
    }

    @PostMapping("/update-tagInfo")
    public String updateTagInfo(UpdateTagInfoVO updateTagInfoVO, Model model){
        int result = tagBackService.updateTagInfo(updateTagInfoVO);
        String updateResultUrl = ControllerUtil.updateResultUrl(result, "redirect:/tag/get-all-tag", model);
        return updateResultUrl;
    }
}
